package com.android.myapplication.view;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.Toast;

import com.android.myapplication.R;
import com.android.myapplication.main.BaseActvity;

public class ImageViewActivity extends BaseActvity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_image);
        init();
        Spinner spinner = findViewById(R.id.spinner_scale_type);

        final String[] type = new String[]{
                ImageView.ScaleType.FIT_XY.name(),
                ImageView.ScaleType.FIT_START.name(),
                ImageView.ScaleType.FIT_CENTER.name(),
                ImageView.ScaleType.FIT_END.name(),
                ImageView.ScaleType.CENTER.name(),
                ImageView.ScaleType.CENTER_CROP.name(),
                ImageView.ScaleType.CENTER_INSIDE.name()
        };
        spinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, type));
        final ImageView imageView = findViewById(R.id.image);
        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                imageView.setScaleType(ImageView.ScaleType.valueOf(type[position]));

            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }

        });


    }

    public void showToast(View v){
        Toast.makeText(this,"点击了按钮", Toast.LENGTH_LONG).show();
    }

}
